/**
 * @Author：ming
 * @Date：2023/10/2 2:09 AM
 * @Filename：Lc114
 */

import java.util.LinkedList;

/**
 * @author ming
 */
public class Lc114 {
    public void flatten(TreeNode root) {
        if(root==null){
            return;
        }
        LinkedList<TreeNode> list = new LinkedList<>();
        getTree(root,list);

        TreeNode head = list.removeFirst();
        head.right = null;
        while (list.size()>0){
            TreeNode temp = list.removeFirst();
            temp.left=null;
            head.right = temp;
            head = head.right;
        }


    }

    public static void getTree(TreeNode root,LinkedList<TreeNode> l){
       if(root==null){
           return;
       }
       l.add(root);
       getTree(root.left,l);
       getTree(root.right,l);
    }




}
